using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using SapaFinance.Domain.Model;

namespace SapaFinance.Domain.EntityFramework
{
    internal class AccountConfiguration : EntityTypeConfiguration<Account>
    {
        public AccountConfiguration()
        {
            ToTable(typeof(Account).Name.ToLower());
            HasKey(x => x.UID);
            Property(x => x.UID).HasColumnName("id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.Number).HasColumnName("accountnumber").IsRequired();
            Property(x => x.Iban).HasColumnName("iban").IsOptional();
            //HasRequired(x => x.Corporation).WithMany(x=>x.Accounts).Map(m => m.MapKey("corporationid")).WillCascadeOnDelete();
            //HasRequired(x => x.Corporation).WithMany(x=>x.Accounts).HasForeignKey(x=>x.corporationid).WillCascadeOnDelete();
            HasRequired(x => x.Bank).WithMany().Map(m => m.MapKey("bankid")).WillCascadeOnDelete();
            HasRequired(x => x.Currency).WithMany().Map(m => m.MapKey("currencyid")).WillCascadeOnDelete(false);
            Property(x => x.IsHidden).HasColumnName("isactive").IsRequired();
            Property(x => x.IsPrimary).HasColumnName("isprimary").IsRequired();
            HasRequired(p => p.CreatedBy).WithMany().Map(m => m.MapKey("createdbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.ChangedBy).WithMany().Map(m => m.MapKey("changedbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.OwnedBy).WithMany().Map(m => m.MapKey("ownedbyid")).WillCascadeOnDelete(false);
        }
    }
}